package com.mooc.swxy.system;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Siaze
 * @date 2022/4/19 22:00
 */
@Data
public class ResponseMap {
    /**
     * 返回状态码
     */
    private int code;

    /**
     * 返回消息
     */
    private String msg;

    /**
     * 返回数据
     */
    private Map<String,Object> data;

    public ResponseMap(int code, String msg, Map data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResponseMap(int code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = new HashMap();
    }
    public ResponseMap() {
        this.data = new HashMap();
    }

    /**
     * @param key  键
     * @param value 值
     *  添加数据
     */
    public ResponseMap putData(String key, Object value) {
        this.data.put(key, value);
        return this;
    }

    /**
     * @param key 键
     * 删除数据
     */
    public ResponseMap removeData(String key){
        this.data.remove(key);
        return this;
    }

    /**
     * @param key 键
     * 获取数据
     */
    public Object getData(String key){
        return this.data.get(key);
    }

    /**
     * @param key 键
     * @param classType 类型
     */
    public <T> T getData(String key, Class<T> classType){
        return this.data.get(key) == null ? null : (T) this.data.get(key);
    }
}
